package com.purong.purong.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;

import com.purong.purong.R;
import com.purong.purong.adapter.GuidePagerAdapter;
import com.purong.purong.fragment.GuideFragment;
import com.purong.purong.util.StatusBarUtil;

import java.util.ArrayList;

/**
 * Created by zengwenjie on 2017/12/12.
 */
public class GuideActivity extends BaseActivity {
    private ViewPager mViewPager;
    private GuidePagerAdapter mAdapter;
    private ArrayList<Fragment> fragmentList=new ArrayList<>();
    private ImageView tagOne,tagTwo,tagThree,tagFour;
    @Override
    public int getRootViewId() {
        return R.layout.activity_gulide;
    }

    @Override
    public void initView() {
        StatusBarUtil.setStatusBarTran(this);
        tagOne=(ImageView)findViewById(R.id.tag_one);
        tagTwo=(ImageView)findViewById(R.id.tag_two);
        tagThree=(ImageView)findViewById(R.id.tag_three);
        tagFour=(ImageView)findViewById(R.id.tag_four);

        mViewPager=(ViewPager)findViewById(R.id.view_pager);
        GuideFragment fragment;
        Bundle bundle;
        fragment=new GuideFragment();
        bundle=new Bundle();
        bundle.putInt("PAGE",GuideFragment.PAGE_ONE);
        fragment.setArguments(bundle);
        fragmentList.add(fragment);
        fragment=new GuideFragment();
        bundle=new Bundle();
        bundle.putInt("PAGE",GuideFragment.PAGE_TWO);
        fragment.setArguments(bundle);
        fragmentList.add(fragment);
        fragment=new GuideFragment();
        bundle=new Bundle();
        bundle.putInt("PAGE",GuideFragment.PAGE_THREE);
        fragment.setArguments(bundle);
        fragmentList.add(fragment);
        fragment=new GuideFragment();
        bundle=new Bundle();
        bundle.putInt("PAGE",GuideFragment.PAGE_FOUR);
        fragment.setArguments(bundle);
        fragmentList.add(fragment);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                setTag(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        mAdapter = new GuidePagerAdapter(getSupportFragmentManager(), fragmentList);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(4);
    }
    private void setTag(int position){
        tagOne.setImageResource(R.drawable.icon_lunbodian_nor);
        tagTwo.setImageResource(R.drawable.icon_lunbodian_nor);
        tagThree.setImageResource(R.drawable.icon_lunbodian_nor);
        tagFour.setImageResource(R.drawable.icon_lunbodian_nor);
        switch (position){
            case 0:
                tagOne.setImageResource(R.drawable.icon_lunbodian_sel);
                break;
            case 1:
                tagTwo.setImageResource(R.drawable.icon_lunbodian_sel);
                break;
            case 2:
                tagThree.setImageResource(R.drawable.icon_lunbodian_sel);
                break;
            case 3:
                tagFour.setImageResource(R.drawable.icon_lunbodian_sel);
                break;
        }
    }
    @Override
    public void initData() {

    }
}
